package mx.netbrain.business;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import mx.netbrain.dao.StorageDao;
import mx.netbrain.model.Status;
import mx.netbrain.model.Storage;

import org.apache.log4j.Logger;

public class StorageBusiness {

	private static final Logger logger = Logger
			.getLogger(StorageBusiness.class);
	private static StorageDao storageDao = new StorageDao();
	private static Storage storage = new Storage();
	private static Status status = new Status();

	public static void save(Integer volId, String volNombre, String volRuta,
			BigDecimal volEspacio, boolean volCompartido) {
		if (volId != null) {
			storage.setId(volId);
		}
		storage.setName(volNombre);
		storage.setRoute(volRuta);
		storage.setSpace(volEspacio);
		storage.setShare(volCompartido);
		status.setId(1);
		storage.setStatus(status);
		storage.setRegister(new Date());
		storageDao.add(storage);
	}

	public static Storage findById(Integer id) {
		logger.info("Se obtiene el volumen: " + id);
		return storageDao.findById(id);
	}

	public static List<Storage> list() {
		return storageDao.list();
	}

	public static void delete(Integer id) {
		storage = findById(id);
		status.setId(2);
		storage.setStatus(status);
		storageDao.add(storage);
	}

}
